import { BasicColumn } from '/@/components/Table';
import { FormSchema } from '/@/components/Table';
// import { rules } from '/@/utils/helper/validator';
import { render } from '/@/utils/common/renderUtils';
import { useI18n } from '/@/hooks/web/useI18n';
const { t } = useI18n('asset.assetInfo.fields');
const { t: common } = useI18n('common');
export const assetInfoFields = {
  name: t('name'),
  cartegory: t('cartegory'),
  useState: t('useState'),
  position: t('position'),
  code: t('code'),
  rfid: t('rfid'),
  user: t('user'),
  custodyDepartment: t('custodyDepartment'),
  specification: t('specification'),
  description: t('description'),
  price: t('price'),
  control: t('control'),
  depreciation: t('depreciation'),
  residuals: t('residuals'),
  releaseDate: t('releaseDate'),
  registrationDate: t('registrationDate'),
  useTime: t('useTime'),
};
export const renderUseState = (text) =>
  render.renderDict(text, 'useState', true, {
    '0': 'green',
    '2': 'blue',
    '3': 'orange',
    '4': 'red',
    '5': 'cyan',
    '6': 'pink',
    '7': 'purple',
  });
//列表数据
export const columns: BasicColumn[] = [
  {
    title: assetInfoFields.name,
    align: 'center',
    dataIndex: 'name',
  },
  {
    title: assetInfoFields.cartegory,
    align: 'center',
    dataIndex: 'cartegory_dictText',
  },
  {
    title: assetInfoFields.useState,
    align: 'center',
    width: 100,
    dataIndex: 'useState',
    customRender: ({ text }) => {
      return renderUseState(text);
    },
  },
  {
    title: assetInfoFields.custodyDepartment,
    align: 'center',
    dataIndex: 'custodyDepartment_dictText',
  },
  {
    title: assetInfoFields.position,
    align: 'center',
    dataIndex: 'position_dictText',
  },
  {
    title: assetInfoFields.code,
    align: 'center',
    dataIndex: 'code',
  },
  {
    title: assetInfoFields.control,
    align: 'center',
    width: 80,
    dataIndex: 'rfidControl',
    customRender: ({ text }) => {
      return render.renderSwitch(text, [
        { text: '是', value: 'Y' },
        { text: '否', value: 'N' },
      ]);
    },
  },
  {
    title: assetInfoFields.rfid,
    align: 'center',
    dataIndex: 'rfid',
  },
  {
    title: assetInfoFields.user,
    align: 'center',
    width: 100,
    dataIndex: 'user_dictText',
  },
  {
    title: assetInfoFields.depreciation,
    align: 'center',
    width: 80,
    dataIndex: 'depreciationRate',
    customRender({ text }) {
      return text ? text + '%' : '';
    },
  },
  {
    title: assetInfoFields.residuals,
    width: 80,
    align: 'center',
    dataIndex: 'residualsRate',
    customRender({ text }) {
      return text ? text + '%' : '';
    },
  },
];
//查询数据
export const searchFormSchema: FormSchema[] = [
  {
    label: assetInfoFields.name,
    field: 'name',
    component: 'JInput',
    componentProps: {
      type: 'like',
    },
    colProps: { span: 6 },
  },
  {
    label: assetInfoFields.cartegory,
    field: 'cartegory',
    component: 'JTreeSelect',
    componentProps: {
      dict: 'asset_category,category_name,id',
      pidField: 'pid',
      pidValue: '0',
      hasChildField: 'has_child',
    },

    colProps: { span: 6 },
  },
  {
    label: assetInfoFields.useState,
    field: 'useState',
    component: 'JDictSelectTag',
    componentProps: {
      dictCode: 'useState',
      showChooseOption: false,
    },
    colProps: { span: 6 },
  },
];
//表单数据
export const formSchema: FormSchema[] = [
  {
    label: assetInfoFields.name,
    field: 'name',
    component: 'Input',
    dynamicRules: () => {
      return [{ required: true }];
    },
  },
  {
    label: assetInfoFields.cartegory,
    field: 'cartegory',
    component: 'JTreeSelect',
    componentProps: {
      dict: 'asset_category,category_name,id',
      pidField: 'pid',
      pidValue: '0',
      hasChildField: 'has_child',
    },
    dynamicRules: () => {
      return [{ required: true, message: `${common('chooseText')}${assetInfoFields.position}!` }];
    },
  },

  {
    label: assetInfoFields.position,
    field: 'position',
    component: 'JTreeSelect',
    componentProps: {
      dict: 'asset_position,position_name,id',
      pidField: 'pid',
      pidValue: '0',
      hasChildField: 'has_child',
    },
    dynamicRules: () => {
      return [{ required: true, message: `${common('chooseText')}${assetInfoFields.position}!` }];
    },
  },
  {
    label: assetInfoFields.custodyDepartment,
    field: 'custodyDepartment',
    component: 'JSelectDept',
    componentProps: {
      isRadioSelection: true,
      checkStrictly: true,
      multiple: false,
    },
    dynamicRules: () => {
      return [{ required: true, message: `${common('chooseText')}${assetInfoFields.custodyDepartment}!` }];
    },
  },
  {
    label: assetInfoFields.price,
    field: 'price',
    component: 'InputNumber',
    componentProps: {
      min: 0,
      precision: 2,
    },
    dynamicRules: () => {
      return [{ required: true }];
    },
  },
  {
    label: assetInfoFields.control,
    field: 'rfidControl',
    component: 'JSwitch',
    componentProps: {},
  },
  {
    label: assetInfoFields.rfid,
    field: 'rfid',
    component: 'RfidSelect',
    show({ values }) {
      return values.rfidControl === 'Y';
    },
  },
  {
    label: assetInfoFields.depreciation,
    field: 'depreciationRate',
    component: 'InputNumber',
    componentProps: {
      min: 0,
      max: 100,
      addonAfter: '%',
      precision: 2,
    },
  },
  {
    label: assetInfoFields.residuals,
    field: 'residualsRate',
    component: 'InputNumber',
    componentProps: {
      min: 0,
      max: 100,
      addonAfter: '%',
      precision: 2,
    },
  },

  {
    label: assetInfoFields.releaseDate,
    field: 'productionDate',
    component: 'DatePicker',
  },

  {
    label: 'assetInfoFields.registrationDate',
    field: 'registrationDate',
    component: 'DatePicker',
  },

  {
    label: assetInfoFields.useTime,
    field: 'life',
    component: 'InputNumber',
    componentProps: {
      min: 1,
      max: 100,
      addonAfter: '月',
    },
  },

  {
    label: assetInfoFields.specification,
    field: 'specification',
    component: 'InputTextArea',
  },
  {
    label: assetInfoFields.description,
    field: 'description',
    component: 'InputTextArea',
  },
  {
    label: '',
    field: 'id',
    component: 'Input',
    show: false,
  },
];

/**
 * 流程表单调用这个方法获取formSchema
 * @param param
 */
export function getBpmFormSchema(_formData): FormSchema[] {
  // 默认和原始表单保持一致 如果流程中配置了权限数据，这里需要单独处理formSchema
  return formSchema;
}
